<?php
    //include 加载模块组件
    include "library/demo.php";
    //require("demo.php");
    //echo com1();

    //属性作用域
    function a1(){
        class Car {
            //public $url;
            //public $title;
            //构造方法
            function __construct( $par1, $par2 ) {
                $this->url = $par1;
                $this->title = $par2;
            }
            //析构函数(实例销毁执行)
            function __destruct(){
                echo 'over';
            }
            //私有属性
            private $price = '1000';
            //不设置方法的访问控制 默认为共有
            public function getTitle(){
                return $this->price;
            }

        }
        $car = new Car('link',10);
        echo $car->url;
    }
    //a1();

    /**
     * 关于继承
     * 子类构造函数不存在则调用父类构造函数
     * self是引用静态类的类名，而$this是引用非静态类的实例名。
     */
    function a2(){
        class Human {
            public $name;
            public $height;
            public $weight;
            //静态方法类似于js中的引用类型的继承prototype.arr = []
            public static $arr = array('a','b');
            function __construct($name,$height,$weight) {
                $this->name = $name;
                $this->height = $height;
                $this->weight = $weight;
            }
            public function eat($food) {
                echo "name: ".$this->name."<br/>";
                echo "height: ".$this->height."<br/>";
                echo "weight: ".$this->weight."<br/>";
            }
        }
        class Nba extends Human {
            public $team;
            public $number;
            function __construct($name,$height,$weight,$team,$number) {
                parent::__construct($name,$height,$weight);
                $this->team = $team;
                $this->number = $number;
            }
            public function info() {
                echo "name: ".$this->name."<br/>";
                echo "height: ".$this->height."<br/>";
                echo "weight: ".$this->weight."<br/>";
                echo "team: ".$this->team."<br/>";
                echo "number: ".$this->number."<br/>";
            }
        }
        $jordan1 = new Nba('jordan','180','60','pig',11);
        //$jordan->info();
        array_push(Human::$arr,"blue","yellow");
        var_dump($jordan1->name);

        $jordan2 = new Human('lisa','170','30');
        var_dump($jordan2->name);
    }
    //a2();


   //关于继承
    function a3(){
        class Car {
            public $speed = 0; //汽车的起始速度是0

            public function speedUp() {
                $this->speed += 10;
                return $this->speed;
            }
        }
        //定义继承于Car的Truck类
         class Truck extends Car {
            public function speedChild() {
                $this->speed = $this->speedUp() + 50;
            }
        }
        $car = new Truck();
        $car->speedChild();
        echo $car->speed;
    }
    //a3();

    //继承(调用父类构造函数)
    function a4(){
        class Car {
           function __construct() {
               print "父类构造函数被调用\n";
           }
        }
        class Truck extends Car {
           function __construct($p) {
               echo $p;
               print "子类构造函数被调用\n";
               parent::__construct();
           }
        }
        $bwm = new Truck(1);
    }
    //a4();

    //final关键字(继承时候不允许重写方法)
    function a5(){
        class Man {
            function eat(){
                echo "eat fanfan";
            }
        }

        class Xiao extends Man{
            public static $demo = 100;
            /*function __construct($demoNumber = 1) {
                $this->demo = $demoNumber;
            }*/
            function eat(){
                echo iao::$demo."eat fanfan";
            }
        }

        $obj =  new Xiao();
        $obj->eat();
    }

    //a5();



?>